// import { login, logout, getUserInfo } from '@/api/login'
import { getTokenByAuthCode, logout, getUserInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'

const useCommonStore = defineStore('common',
  {
    state: () => ({
      reconciliationId: '', // 生成对账单成功之后的结果id,下载对账单Excel
      radio_railway: '0', // 铁路单选（0-智能匹配，1-时间选择）
      radio_start: '0', // 发端
      activePage: "first",
      current_file: {}, // 选择完后本地文件对象
      fileList: [], // 选择的文件列表，
      file_url: '', // 预览文件使用文件url
      show_frame_view: false, // 显示文件预览条件
      formStart: {
        routeIds: []
      },
      formRail: {},
      formGenerate: {}, // 生成对账单的表单
      errorList: [],
      errorCode: '',
      duplicateData: [],
      waybillUnmatchedData: [],
      waybillDuplicatedData: [],
      resultData: [],
      mergeRules: []
    }),
    actions: {
      // 写入数据
      setCommonData(data) {
        return new Promise((resolve, reject) => {
          this.reconciliationId = data.reconciliationId // 生成对账单成功之后的结果id下载对账单Excel
          this.radio_railway = data.radio_railway // 铁路单选（0-智能匹配，1-时间选择）
          this.radio_start = data.radio_start // 发端
          this.activePage = data.activePage
          this.current_file = data.current_file // 选择完后本地文件对象
          this.fileList = data.fileList // 选择的文件列表，
          this.file_url = data.file_url // 预览文件使用文件url
          this.show_frame_view = data.show_frame_view // 显示文件预览条件
          this.formStart = data.formStart
          this.formRail = data.formRail
          this.formGenerate = data.formGenerate // 生成对账单的表单
          this.errorList = data.errorList
          this.errorCode = data.errorCode
          this.duplicateData = data.duplicateData
          this.waybillUnmatchedData = data.waybillUnmatchedData
          this.waybillDuplicatedData = data.waybillDuplicatedData // 发端时间区间
          this.resultData = data.resultData
          this.mergeRules = data.mergeRules
          resolve(data)
        })
      },

      // 获取发起对账页面历史数据
      getCommonData() {
        return new Promise((resolve, reject) => {
          let data = {
            reconciliationId: this.reconciliationId, // 生成对账单成功之后的结果id,下载对账单Excel
            radio_railway: this.radio_railway, // 铁路单选（0-智能匹配，1-时间选择）
            radio_start: this.radio_start, // 铁路单选（0-智能匹配，1-时间选择）
            activePage: this.activePage,
            current_file: this.current_file, // 选择完后本地文件对象
            fileList: this.fileList, // 选择的文件列表，
            file_url: this.file_url, // 预览文件使用文件url
            show_frame_view: this.show_frame_view, // 显示文件预览条件
            formStart: this.formStart,
            formRail: this.formRail,
            formGenerate: this.formGenerate, // 生成对账单的表单
            errorList: this.errorList,
            errorCode: this.errorCode,
            duplicateData: this.duplicateData,
            waybillUnmatchedData: this.waybillUnmatchedData,
            waybillDuplicatedData: this.waybillDuplicatedData, // 发端时间区间
            resultData: this.resultData,
            mergeRules: this.mergeRules
          }
          resolve(data)
        })
      },
    }
  })
export default useCommonStore
